package com.retail.marketing.server.strategy;

import com.retail.marketing.common.req.ComputeReq;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

//折扣优惠卷计算类
@Component
public class DiscountCoupon implements CouponStrategy {
    @Override
    public BigDecimal doActive(ComputeReq req) {
        //获取订单原价格跟满足条件价格作比较
        int i = req.getOrderPrice ().compareTo(req.getMinOrderAmount());
        if (i<0){
            //如果不满足条件就只接返回原价格
            return req.getOrderPrice ();
        }
        //在数据库折扣比率我存的数据是小于10的大于0.1的小数，在这了×0.1转换为0.00，通过百分比计算
        BigDecimal multiply = req.getOrderPrice ().multiply(new BigDecimal("0.1").multiply(req.getDiscountPerentage()));
        return multiply;
    }
}
